import type LayerModelSimple from '../../LayerModel/LayerModelSimple'
import { GeoView } from '../../type/GeoType'
import MapUtil from '../../utils/MapUtil'
import type { Map } from 'mapbox-gl'

/**
 * @ClassName MapboxMapUtil
 * @Description Mapbox地图工具
 * @Author xuyizhuo
 * @Date 2023/11/16 22:14
 */
export default class MapboxMapUtil extends MapUtil<Map> {
    /**
     * 加载地图服务
     * @returns {}
     */
    addService(): LayerModelSimple<Map> {
        return {} as LayerModelSimple<Map>
    }

    /**
     * 获取地图视角
     * @returns {}
     */
    getMapView(): GeoView {
        // 获取地图中心点和地图层级
        const centerPoint = this.realMap.getCenter()
        const zoom = this.realMap.getZoom() + 1
        return { x: centerPoint.lng, y: centerPoint.lat, z: zoom }
    }

    /**
     * 飞行到视角
     * @param {GeoView} geoView 视角信息
     * @returns {MapboxMapUtil}
     */
    flyToView(geoView: GeoView): MapboxMapUtil {
        // 设置地图中心点和层级
        const { x, y, z } = geoView
        this.realMap.setCenter([x, y]).setZoom(z - 1)
        return this
    }
}
